#include "camera.h"

camera::camera()
    : _rotX(0), _rotY(0)
{
    _PositionCam[0] = 0;
    _PositionCam[1] = 0;
    _PositionCam[2] = -70;

    _PositionTarget[0] = 0;
    _PositionTarget[1] = 0;
    _PositionTarget[2] = 0;

}



float camera::getPos(unsigned i) {
    assert(i < 3);
    if (!i)
        return _PositionCam[0];
    else if (i == 1)
        return _PositionCam[1];
    else
        return _PositionCam[2];
}



void camera::addDistance(float dist) {
    _PositionCam[2] += dist;
}



void camera::rotationX() {
    glRotatef(_rotX,1,0,0);
}

void camera::rotationY() {
    glRotatef(_rotY,0,1,0);
}


void camera::updatePosCam(const QPoint pos) {
    _lastPos = pos;
}


/* gestion de la souris qui bouge, version modifie du code du site suivant :
 * http://www.codeforge.com/read/125628/vowelcube.cpp__html
 */



void camera::rotate(QMouseEvent *e) {

    GLfloat dx = GLfloat(e->x() - _lastPos.x());
    GLfloat dy = GLfloat(e->y() - _lastPos.y());

    if (e->buttons() & Qt::LeftButton) {
        _rotY += dx/5;
        _rotX -= dy/5;
    }

    _lastPos = e->pos();
}



